angular.module('service.fileupload',[
    'ngResource'
])
.service('FileUpload', ['$http', '$q', function ($http, $q) {
    //直接上传
    this.uploadFileToUrl1 = function (file,name) {
        var fd = new FormData();
        fd.append('file',file,name);
        fd.append('bizcode', "advert");
        // console.log(fd)
        var deferred = $q.defer();
        $http({
            method: "POST",
            url: uploadUrl,
            data: fd,
            headers: {'Content-Type': undefined},
            transformRequest: angular.identity
        }).then(function (data) {
            deferred.resolve(data);
        }).catch(function (data) {
            deferred.reject(data);
        });
        return deferred.promise;
    };

    /*//压缩上传
    this.uploadFileToUrl = function (file) {
        /!*var fd = new FormData();
         fd.append('file', file);
         console.log(fd)*!/
        file.append('bizcode', "advert");
        var deferred = $q.defer();
        $http({
            method: "POST",
            url: uploadUrl,
            data: file,
            headers: {'Content-Type': undefined},
            transformRequest: angular.identity
        }).then(function (data) {
            deferred.resolve(data);
        }).catch(function (data) {
            deferred.reject(data);
        });
        return deferred.promise;
    }*/
}])
